package com.monitor.util;

import java.io.Serializable;
import java.text.NumberFormat;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

import com.monitor.entity.ErpMateriel;
import com.monitor.entity.ErpMaterielCopy;

public class BlankUtil {
	/**
     * Function:判断字符串是否为空或零长
     * @param str 待检查的字符串变量
     * @return true  字符串为空或零长
     *         false 字符串不为空且不是零长字符串
     */
    public static boolean isBlank(final String str) {
        return (str == null) || (str.trim().length() <= 0);
    }

    /**
     * Function:判断字符是否为空或空格
     * @param cha 待检查的字符变量
     * @return true  字符为空或空格
     *         false 字符不为空且不是空格
     */
    public static boolean isBlank(final Character cha) {
        return (cha == null) || cha.equals(' ');
    }

    /**
     * Function:判断对象是否为空
     * @param obj 待检查的对象变量
     * @return true  对象为空
     *         false 对象不为空
     */
    public static boolean isBlank(final Object obj) {
        return (obj == null);
    }

    /**
     * Function:判断对象数组是否为空或无元素
     * @param objs 待检查的对象数组变量
     * @return true  对象数组为空或无元素
     *         false 对象数组不为空且有元素
     */
    public static boolean isBlank(final Object[] objs) {
        return (objs == null) || (objs.length <= 0);
    }

    /**
     * Function:判断集合对象是否为空或无元素
     * @param obj 待检查的集合对象变量
     * @return true  集合对象为空或无元素
     *         false 集合对象不为空且有元素
     */
    public static boolean isBlank(final Collection<?> obj) {
        return (obj == null) || (obj.size() <= 0);
    }

    /**
     * Function:判断Set对象是否为空或无元素
     * @param obj 待检查的Set对象变量
     * @return true  Set对象为空或无元素
     *         false Set对象不为空且有元素
     */
    public static boolean isBlank(final Set<?> obj) {
        return (obj == null) || (obj.size() <= 0);
    }

    /**
     * Function:判断Serializable对象是否为空
     * @param obj 待检查的Serializable对象变量
     * @return true  Serializable对象为空
     *         false Serializable对象不为空
     */
    public static boolean isBlank(final Serializable obj) {
        return obj == null;
    }

    /**
     * Function:判断Map对象是否为空或无元素
     * @param obj 待检查的Map对象变量
     * @return true  Map对象为空或无元素
     *         false Map对象不为空且有元素
     */
    public static boolean isBlank(final Map<?, ?> obj) {
        return (obj == null) || (obj.size() <= 0);
    }



    public static String listToString(final List<Integer> obj) {
        return obj.toString().substring(1,obj.toString().length()-1).replace(" ","");
    }
    
    public static String listString(final List<String> obj) {
        return obj.toString().substring(1,obj.toString().length()-1).replace(" ","");
    }
    
    //获得两个数的百分比
    public static String toOneHundred(int num1,int num2) {
    	// 创建一个数值格式化对象
    	NumberFormat numberFormat = NumberFormat.getInstance();
    	 
    	// 设置精确到小数点后2位
    	 
    	numberFormat.setMaximumFractionDigits(2);
    	 
    	String result = numberFormat.format((float) num1 / (float) num2 * 100);
    	return result;
    }
    
    //list返回字符串'',''数据
    public static String listStringToString(List<String> list) {
    	StringBuffer sb=new StringBuffer("");
    	for(String str:list) {
    		sb.append("'"+str+"',");
    	}
    	String st=sb.substring(0, sb.length()-1);
    	return st;
    }
    private static byte[] lock = new byte[0];

    // 位数，默认是8位
    private final static long w = 100000000;
    public static String createID() {
        long r = 0;
        synchronized (lock) {
            r = (long) ((Math.random() + 1) * w);
        }

        return System.currentTimeMillis() + String.valueOf(r).substring(1);
    }

    public static ErpMaterielCopy copyMateriel(ErpMateriel materiel) {
    	ErpMaterielCopy copy=new ErpMaterielCopy();
    	if(materiel!=null) {
    		if(materiel.getCorrespondingId()!=null) {
    			copy.setCorrespondingId(materiel.getCorrespondingId());
    		}else {
    			copy.setCorrespondingId(0);
    		}
    		if(materiel.getCustomerId()!=null) {
    			copy.setCustomerId(materiel.getCustomerId());
    		}else {
    			copy.setCustomerId(0);
    		}
	    	copy.setDelectType(materiel.getDelectType());
	    	if(materiel.getFenzu()!=null) {
	    		copy.setFenzu(materiel.getFenzu());
	    	}else {
	    		copy.setFenzu("");
	    	}
	    	if(materiel.getKucunorliucun()!=null) {
	    		copy.setKucunorliucun(materiel.getKucunorliucun());
	    	}else {
	    		copy.setKucunorliucun("");
	    	}
	    	copy.setMaterielBrand(materiel.getMaterielBrand());
	    	if(materiel.getMaterielDot()!=null) {
	    		copy.setMaterielDot(materiel.getMaterielDot());
	    	}else {
	    		copy.setMaterielDot("");
	    	}
	    	if(materiel.getMaterielEqcode()!=null) {
	    		copy.setMaterielEqcode(materiel.getMaterielEqcode());
	    	}else {
	    		copy.setMaterielEqcode("");
	    	}
	    	if(materiel.getMaterielFlowId()!=null) {
	    		copy.setMaterielFlowId(materiel.getMaterielFlowId());
	    	}else {
	    		copy.setMaterielFlowId(0);
	    	}
	    	if(materiel.getMaterielId()!=null) {
	    		copy.setMaterielId(materiel.getMaterielId());
	    	}else {
	    		copy.setMaterielId(0);
	    	}
	    	if(materiel.getMaterielInvoiceType()!=null) {
	    		copy.setMaterielInvoiceType(materiel.getMaterielInvoiceType());
	    	}else {
	    		copy.setMaterielInvoiceType(0);
	    	}
	    	copy.setMaterielLoad(materiel.getMaterielLoad());
	    	copy.setMaterielModel(materiel.getMaterielModel());
	    	copy.setMaterielName(materiel.getMaterielName());
	    	copy.setMaterielNumber(materiel.getMaterielNumber());
	    	copy.setMaterielPlace(materiel.getMaterielPlace());
	    	if(materiel.getMaterielProductionId()!=null) {
	    		copy.setMaterielProductionId(materiel.getMaterielProductionId());
	    	}else {
	    		copy.setMaterielProductionId("");
	    	}
	    	copy.setMaterielRefurbished(materiel.getMaterielRefurbished());
	    	if(materiel.getMaterielRfid()!=null) {
	    		copy.setMaterielRfid(materiel.getMaterielRfid());
	    	}else {
	    		copy.setMaterielRfid("");
	    	}
	    	copy.setMaterielSpecifications(materiel.getMaterielSpecifications());
	    	copy.setMaterielState(materiel.getMaterielState());
	    	copy.setMaterielStorageDate(materiel.getMaterielStorageDate());
	    	copy.setMaterielStoragePrice(materiel.getMaterielStoragePrice());
	    	if(materiel.getMaterielTaiyaid()!=null) {
	    		copy.setMaterielTaiyaid(materiel.getMaterielTaiyaid());
	    	}else {
	    		copy.setMaterielTaiyaid("");
	    	}
	    	copy.setMaterielUnit(materiel.getMaterielUnit());
	    	if(materiel.getQichutype()!=null) {
	    		copy.setQichutype(materiel.getQichutype());
	    	}else {
	    		copy.setQichutype("");
	    	}
	    	copy.setState(materiel.getState());
	    	copy.setTai(materiel.getTai());
	    	copy.setWarehouseId(materiel.getWarehouseId());
	    	copy.setZhiNeng(materiel.getZhiNeng());
    	}
    	return copy;
    }
}
